#This Script Queries LMTools and Sends and Email with usage when full
#Written by Jason Finnigan
#X Should be Equal to Total Number of Seats

$Email = cd "C:\Program Files\Autodesk Network License Manager\"
$Lmtools = .\lmutil.exe lmstat -f [LicesneNumber]
$Body = $Lmtools -replace ",","`n"
If (($Lmtools -like '*Total of X licenses in use*') -and (!(Test-Path -Path C:\Scripts\Autodesk.txt -PathType Leaf))){$MailBody= $Body + $Email.mail
$MailSubject= "Autodesk License Full"
$SmtpClient = New-Object system.net.mail.smtpClient
$SmtpClient.host = "SMTP Relay"
$MailMessage = New-Object system.net.mail.mailmessage
$MailMessage.from = "FROM@MAIL.COM"
$MailMessage.To.add("TO@MAIL.com")
$MailMessage.IsBodyHtml = 0
$MailMessage.Subject = $MailSubject
$MailMessage.Body = $MailBody
$SmtpClient.Send($MailMessage)
New-Item 'C:\Scripts\Autodesk.txt' -type file -force -value 1
}
ElseIf  (!($Lmtools -like '*Total of X licenses in use*')) {Remove-Item 'C:\Scripts\Autodesk.txt'
}
Else {Exit
}